<template>
  <a-modal
    :title="title"
    width="25%"
    :bodyStyle="{ height: '150px' }"
    :visible="visible"
    :confirmLoading="loading"
    :footer="null"
    @cancel="
      () => {
        this.visible = false
      }
    "
  >
    <template>
      <a-row :gutter="10" style="margin-top: 30px;">
        <a-col :span="12" style="text-align: center;">
          <!-- :md="14" :sm="24" -->
          <a-upload name="file" :multiple="true" :action="$rootUrl + leading" :headers="headers" @change="handleChange">
            <a-button type="primary"> <a-icon type="upload" /> 上传数据 </a-button>
          </a-upload>
        </a-col>

        <a-col :span="12" style="text-align: center;">
          <a-button
            @click="
              () => {
                this.visible = false
              }
            "
            ><a-icon type="download" />
            <!-- <a :href=" $rootUrl+templet">下载模板表</a> -->
            <a @click="LoadClick($rootUrl + templet)">下载模板表</a>
            <!--  -->
          </a-button>
        </a-col>
      </a-row>
    </template>
  </a-modal>
</template>

<script>
import Token from '../../utils/cache/TokenCache'
import { download } from '@/components/download'
// import ProjectSelect from '@/components/PB/ProjectSelect'
export default {
  components: {
    Token,
    // ProjectSelect
  },
  props: {
    parentObj: Object,
    // rootUrl:$rootUrl,
    leading: { type: String, required: false },
    templet: { type: String, required: false }
  },
  data() {
    return {
      layout: {
        labelCol: { span: 5 },
        wrapperCol: { span: 18 }
      },
      lohao: [],
      visible: false,
      loading: false,
      rules: {},
      title: '',
      headers: {
        authorization: 'Bearer ' + Token.getToken()
      },
      entity: {
        ProjectId: ''
      }
    }
  },
  methods: {
    init() {
      this.visible = true
    },
    openForm(id, title) {
      this.init()
      this.title = title
    },
    handleChange(info) {
      console.log(info)
      if (this.templet == '/PB/PB_MaterialType/ExportToExcel') {
        this.$set(info.file, 'ProjectId', this.entity.ProjectId)
        this.$set(info.file, 'BuildingNumberID', this.entity.BuildingNumberID)
      }
      if (info.file.status !== 'uploading') {
        console.log(info.file, info.fileList)
      }
      if (info.file.status === 'done') {
        if (info.file.response.Success === false) {
          this.$message.error(`${info.file.name}文件,${info.file.response.Msg},请检查文件内容！ `)
        } else {
          this.$message.success(`${info.file.name}  文件上传成功！`)
        }
        this.visible = false
      } else if (info.file.status === 'error') {
        this.$message.error(`${info.file.name} 文件上传失败！`)
      }
    },
    LoadClick(url) {
      download(url)
    }
  }
  // watch: {
  //   entity: {
  //     deep: true,
  //     handler(a, b) {
  //       console.log(a, b)
  //     }
  //   }
  // }
}
</script>
